/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
package hello;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

public class MyGameCanvas extends GameCanvas implements Runnable
{
private boolean isRunning;

private int pressedKey=0;
private HelloMIDlet mParent;
public String m_nowStatus = null;

public Image drawImg = null;

public MyGameCanvas( HelloMIDlet parent )
{
   super( false );
   mParent = parent;
}
public void start()
{
    isRunning = true;
    Thread t = new Thread( this );
    t.start();
}

public void run()
{
    Graphics g = getGraphics();
    
    while( isRunning )
    {
        //input();
        drawScreen(g);

        try
        {
            Thread.sleep(100);
        }
        catch( InterruptedException e )
        {
            
        }
    }
}

/*
void input()
{
   pressedKey = getKeyValue( getKeyStates() );
}
 * */

protected void keyPressed( int keycode )
{
    pressedKey = keycode;
    BTProcessor.GetInst().SendKeyEvent(keycode , true );
}

protected void keyReleased( int keycode )
{
    pressedKey = keycode;
    BTProcessor.GetInst().SendKeyEvent( keycode , false );
}

protected void keyRepeated( int keycode )
{
    pressedKey = keycode;
    BTProcessor.GetInst().SendKeyEvent(keycode , true );
}

int getClipWidth()
{
    Graphics g = getGraphics();
    return g.getClipWidth();
}

int getClipHeight()
{
    Graphics g = getGraphics();
    return g.getClipHeight();
}

void drawScreen(Graphics g)
{
    g.setColor( 0xffffff );
    g.fillRect(0, 0, getWidth(), getHeight() );
    g.setColor(0x0000ff );
    
    if( drawImg != null )
        g.drawImage( drawImg , 0 , 0 , 0 );
    
    if( pressedKey != 0 )
    {
        g.drawString( "Pressed:" + String.valueOf(pressedKey) , 0, 0, Graphics.TOP | Graphics.LEFT );
    }

    if( m_nowStatus != null )
    {
        g.drawString( "NowStatus:" + m_nowStatus , 0 , 10 , Graphics.TOP | Graphics.LEFT );
    }
    
    flushGraphics();
}
}
